class UsuariosController < ApplicationController
  before_filter :check_authentication, :except => [:signin]
  
  def check_authentication
    unless session[:user]
      session[:intended_action] = action_name
      session[:intended_controller] = controller_name
      redirect_to :action => "signin"
    end
  end

  def signin
    if request.post?
      session[:user] = Usuario.authenticate(params[:usuario], params[:secreto]).id
      redirect_to :action => session[:intended_action],
                  :controller => session[:intended_controller]
    end
  end

  def signout
    session[:user] = nil
    redirect_to "/"
  end
  
  active_scaffold :usuarios do |config|
    config.label = "Gestión de Usuarios"
    config.columns = [:usuario]
    config.columns.add :contrasena
    list.columns.exclude :contrasena
  end
  
end
